home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / UPUTZC.C < prev    next >
C/C++ Source or Header  |  1992-09-09  |  7KB  |  204 lines

  1. /* UputZCompact().   Drawing image in ZCompact format.
  2.  *
  3.  * UNCHAINED mode version. For mode 13h (MCGA), C4 off (UNCHAINED).
  4.  *
  5.  * Uses following coding method:
  6.  *
  7.  * Line    ends by a 0, 0 (color code = 0, counter = 0)
  8.  * Picture ends by rows counter.
  9.  *
  10.  *     +7-------------------6+5----------------------0+
  11.  *     | counter (1 till 3)  |  color code (0 - 63)   |
  12.  *     +---------------------+------------------------+
  13.  * or
  14.  *     +7-6+5------------0+    +7---------------------0+
  15.  *     | 0 | color code   |    |  counter              |
  16.  *     +---+--------------+    +-----------------------+
  17.  *
  18.  * Functions:
  19.  *      UputZCompact().
  20.  *
  21.  * See Also: cputc.c
  22.  * Portability: BORLANDC
  23.  *                                       (c) erdy 1992
  24.  * $Header: $
  25.  */
  26. #pragma inline
  27. #include "far.h"
  28. #include "vgaprefx.h"
  29. #include "vgadrv.h"
  30. #include "screen.h"
  31.  
  32. static void near map_masks(void) /* Just to situate the mask table */
  33. {
  34. #if 0
  35.     asm lmsk label byte
  36.         asm db 0xF, 0x7, 0x3, 0x1;
  37. #endif
  38.     asm rmsk label byte
  39.         asm db 0x0, 0x1, 0x3, 0x7;
  40. }
  41.  
  42. #ifdef ZC_PREPARED
  43.         void UputZCompact(char far *image, int mask, int offset, int rows)
  44. #else
  45.         void UputZCompact(char far *image, int x, int y, int rows)
  46. #endif ZC_PREPARED
  47. {
  48.     _CX = rows;
  49.         _ES = Scdraw_seg;
  50.  
  51.         asm mov dx, VGA_SER_ADR;      /* Point the gate to Map Mask Register */
  52.         asm mov al, _SER_MAPMASK;
  53.     asm out dx, al;
  54.  
  55.     asm push ds;
  56.     asm pop bx;
  57.  
  58.     asm lds si, image;
  59.  
  60. #       ifdef ZC_PREPARED
  61.         asm mov di, offset;
  62.         asm mov ax, mask;
  63.         asm push bp;
  64.         asm mov bp, ax;         /* Initial starting offset */
  65. #       else  ZC_PREPARED
  66.         asm mov ax, y;          /* Get argument */
  67.         asm mov dx, BPERROW;
  68.         asm mul dx;
  69.  
  70.         asm mov dx, x;          /* Get argument */
  71.         asm mov di, dx;
  72.         asm shr di, 1;          /* Divide di by 4 */
  73.         asm shr di, 1;
  74.         asm and dx, 3;
  75.         asm add di, ax;
  76.  
  77.         asm push bp;
  78.         asm mov bp, dx;         /* Get initial starting offset */
  79. #       endif ZC_PREPARED
  80.     asm push bx;
  81.     asm cld;
  82.     /*
  83.      * Scanline loop. CX contains nrows.
  84.      */
  85. Loop:
  86.         asm push cx;                    /* Loop counter */
  87.         asm push bp;                    /* Starting offset */
  88.         asm push di;                    /* Save DI */
  89.  
  90.         asm mov bh, byte ptr cs:rmsk[bp];/* Starting mask */
  91.  
  92.         for (;;) {
  93.             asm lodsb;              /* al <- ds:[si++]; get next byte */
  94.             asm mov dl, al;         /* Save color code */
  95.  
  96.             asm rol al, 1;          /* Get counter */
  97.                         asm rol al, 1;          /* = shr al, 6 */
  98.                         asm and ax, 3;          /* ah = 0, al &= 3 */
  99.             asm jne short OKCounter;
  100.                 asm lodsb;      /* Long counter */
  101.                 if (_AL == 0) { /* End of this scanline */
  102. #if 0
  103.                     if (_DL == 0)   /* Next scan line */
  104.                         break;
  105.  
  106.                     asm mov ax, ds;
  107.                     if (_DL == 1) { /* Next colormap */
  108.                                                 asm add ax, 4; /* Shift to next colormap */
  109.                                                 asm sub si, 0x40; /* Shift to 4 paragraphs size */
  110.                     }
  111.                     if (_DL == 2) { /* Previous colormap */
  112.                                                 asm sub ax, 4; /* Shift to next colormap */
  113.                                                 asm add si, 0x40; /* Shift to 4 paragraphs size */
  114.                     }
  115.                     asm mov ds, ax;
  116. #endif
  117.                     break;
  118.                 }
  119. OKCounter:
  120.             asm not bh;             /* Starting Mask */
  121.  
  122.             /* Add previous offset. Now it contains length
  123.              * counted from the left edge of 4-pixels group.
  124.              * (AH already zero).
  125.              */
  126.             asm add ax, bp;         /* Add previous offset */
  127.             asm mov cx, ax;         /* Save length */
  128.             asm and ax, 3;          /* Get plane mask index */
  129.             asm shr cx, 1;          /* Divide by 4 */
  130.             asm shr cx, 1;
  131.  
  132.             if (_DL == 0) {         /* Zero color code -> skipping */
  133.                 asm mov bp, ax; /* Save mask */
  134.                 asm add di, cx; /* Advance the index */
  135.                 asm mov bh, byte ptr cs:rmsk[bp];/* Get start mask */
  136.                 continue;
  137.             }
  138. Drawing:
  139.             /* Color map table must reside at segment:0.
  140.              */
  141.                         asm and dx, 0x3F;               /* Mask off color code */
  142.             asm mov bp, dx;                 /* Put color index into bp */
  143.                         asm mov dl, byte ptr ds:[bp];   /* Map color code */
  144.  
  145.             asm mov bp, ax;                 /* Now save offset */
  146.                         asm mov bl, byte ptr cs:rmsk[bp];/* Get end mask */
  147.             asm mov ah, dl;                 /* Put mapped color */
  148.                         asm mov dx, VGA_SER_GATE;
  149.  
  150.             asm dec cx;                     /* ...altering flags */
  151.             asm jg  short Cont;             /* If cx > 0 - cx groups */
  152.             asm je  short Next;             /* If cx == 0 - Next group */
  153.  
  154. Piece:                  /* Just a piece of 4-group */
  155.                 asm mov al, bl;         /* End mask */
  156.                 asm and al, bh;         /* Compute mask */
  157.                 asm out dx, al;         /* Set mask */
  158.                 asm mov byte ptr es:[di], ah;/* Write the color */
  159.                 asm mov bh, bl;         /* New mask */
  160.                 continue;
  161.             {
  162. Next:
  163.             /* Starting piece */
  164.             asm mov al, bh;              /* Starting mask */
  165.             asm out dx, al;              /* Set Mask */
  166.             asm mov byte ptr es:[di], ah;/* Write the color */
  167.             asm inc di;                  /* Advance the address */
  168.             /* Ending piece */
  169.             asm mov al, bl;         /* End mask */
  170.             asm out dx, al;         /* Set Mask */
  171.                         asm mov byte ptr es:[di], ah;/* Write the color */
  172.                         asm mov bh, bl;         /* New mask */
  173.             continue;
  174.  
  175. Cont:                   /* Number of entire 4-groups */
  176.             /* Starting piece */
  177.             asm mov al, bh;              /* Starting mask */
  178.                         asm out dx, al;              /* Set Mask */
  179.             asm mov byte ptr es:[di], ah;/* Write the color */
  180.             asm inc di;                  /* Advance the address */
  181.                         asm mov al, 0xF;             /* All planes   */
  182.                         asm out dx, al;              /* Set Mask     */
  183.             asm mov al, ah;              /* Fill value   */
  184.             asm rep stosb;               /* Write colors */
  185.             /* Ending piece */
  186.             asm mov al, bl;              /* End mask */
  187.             asm out dx, al;              /* Set Mask */
  188.             asm mov byte ptr es:[di], ah;/* Write the color */
  189.             asm mov bh, bl;              /* New mask */
  190.             continue;
  191.             }
  192.         }
  193.         asm pop di;
  194.         asm pop bp;                             /* Initial starting offset */
  195.         asm pop cx;                             /* æτÑΓτ¿¬ µ¿¬½á */
  196.         asm add di, BPERROW;
  197.     asm dec cx;
  198.     asm jcxz short Exit;
  199.     asm jmp near Loop;
  200. Exit:
  201.     asm pop ds;
  202.     asm pop bp;
  203.     return;
  204. }